import 'package:flutter/cupertino.dart';
import 'dart:math';
import 'SizeConverter.dart';
import 'SourceType.dart';

///素材数据源接口
abstract class SourceInterface extends ChangeNotifier {
  //素材唯一id
  int id = 0;

  //素材名字
  String name = "";

  //素材类型
  int sourceType = SourceType.TYPE_TEXT;

  ///屏幕尺寸信息
  @SizeConverter()
  Size screenSize = Size.zero;

  //构造方法
  SourceInterface() {
    id = createId();
  }

  //创建id
  int createId() {
    return DateTime.now().millisecondsSinceEpoch + Random().nextInt(1000);
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) || other is SourceInterface && runtimeType == other.runtimeType && id == other.id;

  @override
  int get hashCode => id;

  Map<String, dynamic> toJson();
}
